import csv
from pathlib import Path
import matplotlib.pyplot as plt
from datetime import datetime

path = Path('data/2021full.csv')
lines = path.read_text().splitlines()

reader = csv.reader(lines)
header_row = next(reader)

# 打印位置和名称
for i, col in enumerate(header_row):
    print(i, col)

# 提取数据,最高和最低气温
highs,lows,dates = [],[],[]
for row in reader:
    current_date = datetime.strptime(row[2],'%Y/%m/%d')
    dates.append(current_date)
    high = int(row[6])
    highs.append(high)
    lows.append(int(row[7]))

plt.style.use('seaborn')

# 获取绘图
fig,ax = plt.subplots()
ax.plot(dates, highs, color='red', alpha=0.5)
ax.plot(dates, lows, color='blue', alpha=0.5)
ax.fill_between(dates, highs, lows, facecolor='yellow', alpha=0.1)

#设置绘图格式
ax.set_title("temperatures day")
ax.set_xlabel('date')
fig.autofmt_xdate()
ax.set_ylabel('temperatures')
ax.tick_params(labelsize=16)

plt.show()


